/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Forms;

/**
 *
 * @author Owner
 */


import Classes.*;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class AddGrades extends javax.swing.JFrame {

    static MInterface mi;
    String port;
    _Login l = new _Login();
    static User cUser;
    
    DefaultTableModel dtm;
    ArrayList<Object> list;
    ArrayList<Object> list1;
    ArrayList<Object> subjects = null;
    ArrayList<Object> gradeList1 = null;
    ArrayList<Object> gradeList2 = null;
    ArrayList<Object> classlevel = null;
    ArrayList<Object> quarter = null;
    String userID;
    String usertID;
    String sub1;
    String sub2;
    String subres1;
    String subres2;
    String combo;
    String sy;
    String a2;
    String a3;
    String val;
    String idno;
    String name;
    String cl;
    String clselected;
    String subselected;
    int val1;
    String qid;
    String qname;
    String qstat;
    String ggrade;
    String gquartername;
    String gsubject;
    int a33;
    String jcomboselected;
    /**
     * Creates new form AddGrades
     */
    public AddGrades(MInterface i, User u) {
        initComponents();
        this.setLocationRelativeTo(getRootPane());
        
         mi = i;
        port = l.serverAdd;        
        
        try{
            userID = u.getID();
            usertID = u.getType();
            System.out.println(usertID);
             timeL.setText(mi.getCurrentTime());
            dateL.setText(mi.getCurrentDate());
                
             sy = null;
            if (mi.getCurrentDate().compareTo((mi.get("get-endsy", mi.getCurrentDate(), "")) + "") > 0) {
                sy = mi.getToday() + "-" + mi.getNext();
            } else if (mi.getCurrentDate().compareTo((mi.get("get-endsy", mi.getCurrentDate(), "")) + "") < 0) {
                sy = mi.getPast() + "-" + mi.getToday();              
            }
            
            if(usertID.matches("Adviser")){
//                list = mi.getList1("gradeManage22", userID);
//                 list1 = mi.getList1("gradeManage22", userID);
            ArrayList<Grades1> s = new ArrayList<Grades1>();
            for(int x = 0; x < list.size(); x++) {
            s.add((Grades1) list.get(x));
            
            }
            
            
             
                 
             dtm = new DefaultTableModel(new String[] {gaGradeTbl.getColumnName(0), gaGradeTbl.getColumnName(1), gaGradeTbl.getColumnName(2), gaGradeTbl.getColumnName(3), gaGradeTbl.getColumnName(4), gaGradeTbl.getColumnName(5)}, 0);
           
             gaGradeTbl.setModel(dtm);
            
            for(int x = 0; x < s.size(); x++) {
           gaGradeTbl.removeAll();
            dtm.insertRow(x, new Object[] {s.get(x).getidno(),s.get(x).getname(),combo,s.get(x).getfirst(), s.get(x).getsecond(),s.get(x).getthird(),s.get(x).getfourth()});
            }
            
                 
            }else if(usertID.matches("Administrator")){
            list = mi.getList("gradeManage");
         //   list1 = mi.getList4("gradeManage22", userID);
            list1 = mi.getList("gradeManage");
           //  list = mi.getList("gradeManage");
            ArrayList<Grades1> s = new ArrayList<Grades1>();
            for(int x = 0; x < list.size(); x++) {
                Grades1 a = (Grades1) list.get(x);
               // System.out.println(list.get(x) + " | " + sy);
                    //s.add((Grades1) list.get(x));
              //a if(a.getsection().equals(sy)) s.add((Grades1) list.get(x));
                s.add((Grades1) list.get(x));
            
            }
            
            dtm = new DefaultTableModel(new String[] {gaGradeTbl.getColumnName(0), gaGradeTbl.getColumnName(1), gaGradeTbl.getColumnName(2), gaGradeTbl.getColumnName(3), gaGradeTbl.getColumnName(4), gaGradeTbl.getColumnName(5), gaGradeTbl.getColumnName(6), gaGradeTbl.getColumnName(7)}, 0);
            gaGradeTbl.setModel(dtm);
            for(int x = 0; x < s.size(); x++) {
//                String a = s.get(x).getidno();
//                String a1 = s.get(x).getname(); // name
//                String a2 = s.get(x).getsection();//syname
                a2 = s.get(x).getstuID();
                sub2  = s.get(x).getcname();
                
               // System.out.println(a2);
    
          //  gaGradeTbl.removeAll();
           dtm.insertRow(x, new Object[] {s.get(x).getidno(),s.get(x).getname(),combo,s.get(x).getfirst(), s.get(x).getsecond(),s.get(x).getthird(),s.get(x).getfourth()});
           val = s.get(x).getidno();
           name = s.get(x).getname();
           sub1  = s.get(x).getsy();
           
            }
            }
            
             quarter = mi.getList("quarter");
            ArrayList<Quarter> q = new ArrayList<Quarter>();
            for(int x100 = 0; x100 < quarter.size(); x100++) {
            Quarter a1 = (Quarter) quarter.get(x100);
            qid = a1.getid();
            qname = a1.getname();
            qstat = a1.getstatus();
            }
            
            
            
             
            
            classlevel = mi.getList("getlist-classlevels");
            ArrayList<ClassLevel> cc = new ArrayList<ClassLevel>();
            for(int c = 0; c < classlevel.size();c++){
                cc.add((ClassLevel) classlevel.get(c));   
                cl = cc.get(c).getClassName();
                jComboBox5.addItem(cl);
            }
            
//                subjects = mi.getList2("subjectManage", sub1, sub2);
//                ArrayList<Subject> s12 = new ArrayList<Subject>();   
//                for(int x12 = 0; x12 < subjects.size(); x12++) {
//                s12.add((Subject) subjects.get(x12));                
//                subres1 = s12.get(x12).getSubjName();
//                subres2 = s12.get(x12).getsubID();
//                jComboBox1.addItem(subres1);   
//            }
            

        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bannerL = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane48 = new javax.swing.JScrollPane();
        gaGradeTbl = new javax.swing.JTable();
        jComboBox1 = new javax.swing.JComboBox();
        dateL = new javax.swing.JLabel();
        timeL = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jToggleButton1 = new javax.swing.JToggleButton();
        jToggleButton2 = new javax.swing.JToggleButton();
        jToggleButton3 = new javax.swing.JToggleButton();
        jToggleButton4 = new javax.swing.JToggleButton();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jComboBox4 = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jComboBox5 = new javax.swing.JComboBox();

        bannerL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/banner.jpg"))); // NOI18N
        bannerL.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jSeparator1.setForeground(new java.awt.Color(0, 0, 0));

        jScrollPane48.setBackground(new java.awt.Color(255, 255, 255));

        gaGradeTbl.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        gaGradeTbl.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID Number", "Student", "Subject", "1st Quarter", "2nd Quarter", "3rd Quarter", "4th Quarter", "Average"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        gaGradeTbl.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gaGradeTblMouseClicked(evt);
            }
        });
        jScrollPane48.setViewportView(gaGradeTbl);

        jComboBox1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBox1MouseClicked(evt);
            }
        });
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        dateL.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        dateL.setText("mm/dd/yyyy");

        timeL.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        timeL.setText("hh:mm am/pm");

        jTextField1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTextField1.setForeground(new java.awt.Color(204, 204, 204));
        jTextField1.setText("Search...");

        jButton4.setText("Search");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Subject:");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel6.setText("General Average");

        jToggleButton1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jToggleButton1.setText("Unlock 1st Grading");

        jToggleButton2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jToggleButton2.setText("Unlock 3rd Grading");

        jToggleButton3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jToggleButton3.setText("Unlock 2nd Grading");

        jToggleButton4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jToggleButton4.setText("Unlock 4th Grading");

        jButton2.setText("Cancel");

        jButton1.setText("Save");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText("Edit");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 992, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 784, Short.MAX_VALUE)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2)
                        .addGap(19, 19, 19))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jToggleButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jToggleButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jToggleButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jToggleButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 317, Short.MAX_VALUE)
                        .addComponent(jLabel6)
                        .addGap(18, 18, 18))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jToggleButton1)
                    .addComponent(jToggleButton3)
                    .addComponent(jToggleButton2)
                    .addComponent(jToggleButton4)
                    .addComponent(jLabel6))
                .addGap(17, 17, 17)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
                .addContainerGap())
        );

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setText("Adviser:");

        jComboBox3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setText("School Year:");

        jComboBox4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel5.setText("ClassLevel");

        jComboBox5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jComboBox5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(19, 19, 19)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jButton4))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(dateL)
                                    .addGap(38, 38, 38)
                                    .addComponent(timeL))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel3)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(27, 27, 27)
                                    .addComponent(jLabel4)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel5)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(bannerL, javax.swing.GroupLayout.PREFERRED_SIZE, 1012, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane48))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 1001, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(21, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(bannerL, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dateL, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(timeL))
                .addGap(1, 1, 1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBox1)
                    .addComponent(jLabel3)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane48, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(145, 145, 145)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(579, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void gaGradeTblMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gaGradeTblMouseClicked
//                if(evt.getClickCount() == 2) {
//               
//            int x = gaGradeTbl.getSelectedColumn();
//            while(x != 0) {
//                x--;
//            }
//            int y = gaGradeTbl.getSelectedRow();
//            val = (String) gaGradeTbl.getValueAt(y, x);
//            System.out.println(val);
//            
//            try{
//                
//               
//////                   gradeList1 = mi.getList1("gradeManage2", val);
////                 ArrayList<Grades1> uu1 = new ArrayList<Grades1>();
////                 for(int x11 = 0; x11 < gradeList1.size(); x11++) {
////                 uu1.add((Grades1) gradeList1.get(x11));
////            
////                 }
////                 
////                 for(int x11 = 0; x11 < uu1.size(); x11++) {
////               gaGradeTbl.removeAll();
////                dtm.insertRow(x11, new Object[] {val,name,uu1.get(x11).getsubject(),uu1.get(x11).getfirst(), uu1.get(x11).getsecond(),uu1.get(x11).getthird(),uu1.get(x11).getfourth()});
////           
////            }
//                
//                 gradeList2 = mi.getList4("gradeManage1",val);
//                ArrayList<GradesNew> uu1 = new ArrayList<GradesNew>();
//                for (int x11 = 0; x11 < gradeList2.size(); x11++) {
//                    uu1.add((GradesNew) gradeList2.get(x11));
//                    ggrade = uu1.get(x11).getgrade();
//                    gquartername = uu1.get(x11).getquartername();
//                    gsubject = uu1.get(x11).getsubject();
//
//                }
//                
//                if(gquartername.equals("First Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
//                    for (int x11 = 0; x11 < uu1.size(); x11++) {
//                    dtm.setValueAt(ggrade, y, 3);
//                }
//                }else if(gquartername.equals("Second Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
//                for (int x11 = 0; x11 < uu1.size(); x11++) {
//                    dtm.setValueAt(ggrade, y, 4);
//                }
//                }else if(gquartername.equals("Third Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
//                for (int x11 = 0; x11 < uu1.size(); x11++) {
//                    dtm.setValueAt(ggrade, y, 5);
//                }
//                }else if(gquartername.equals("Fourth Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
//                for (int x11 = 0; x11 < uu1.size(); x11++) {
//                    dtm.setValueAt(ggrade, y, 6);
//                }
//                }
//              
//            
//                
//            }catch(Exception e){
//            }
//                }
   }//GEN-LAST:event_gaGradeTblMouseClicked

    private void jComboBox1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox1MouseClicked
       
    }//GEN-LAST:event_jComboBox1MouseClicked

                 
    
        

    
    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
//         combo = (String) jComboBox1.getSelectedItem();
//         
//           ArrayList<Grades1> s = new ArrayList<Grades1>();
//            for(int x = 0; x < list.size(); x++) {
//                Grades1 a = (Grades1) list.get(x);
//               // System.out.println(list.get(x) + " | " + sy);
//                    //s.add((Grades1) list.get(x));
//               if(a.getsection().equals(sy)) s.add((Grades1) list.get(x));
//              //  s.add((Grades1) list.get(x));
//            
//            }
//             dtm = new DefaultTableModel(new String[] {gaGradeTbl.getColumnName(0), gaGradeTbl.getColumnName(1), gaGradeTbl.getColumnName(2), gaGradeTbl.getColumnName(3), gaGradeTbl.getColumnName(4), gaGradeTbl.getColumnName(5), gaGradeTbl.getColumnName(6), gaGradeTbl.getColumnName(7)}, 0);
//            gaGradeTbl.setModel(dtm);
//            for(int x = 0; x < s.size(); x++) {
////                String a = s.get(x).getidno();
////                String a1 = s.get(x).getname(); // name
////                String a2 = s.get(x).getsection();//syname
//                sub2  = s.get(x).getcname();
//                sub1  = s.get(x).getsy();
//        
//              gaGradeTbl.removeAll();
//                dtm.insertRow(x, new Object[] {s.get(x).getidno(),s.get(x).getname(),combo,s.get(x).getfirst(), s.get(x).getsecond(),s.get(x).getthird(),s.get(x).getfourth()});
//           
//            }
        try{
               subselected = jComboBox1.getSelectedItem().toString();
                list = mi.getList4("gradeManage2",clselected);
            ArrayList<Grades1> s = new ArrayList<Grades1>();
            for(int x = 0; x < list.size(); x++) {
                Grades1 a = (Grades1) list.get(x);
                s.add((Grades1) list.get(x));
            
            }
          dtm = new DefaultTableModel(new String[] {gaGradeTbl.getColumnName(0), gaGradeTbl.getColumnName(1), gaGradeTbl.getColumnName(2), gaGradeTbl.getColumnName(3), gaGradeTbl.getColumnName(4), gaGradeTbl.getColumnName(5), gaGradeTbl.getColumnName(6), gaGradeTbl.getColumnName(7)}, 0);
            gaGradeTbl.setModel(dtm);
            for(int x = 0; x < s.size(); x++) {
//                String a = s.get(x).getidno();
//                String a1 = s.get(x).getname(); // name
//                String a2 = s.get(x).getsection();//syname
                a2 = s.get(x).getstuID();
                sub2  = s.get(x).getcname();
                
               // System.out.println(a2);
    
          //  gaGradeTbl.removeAll();
           dtm.insertRow(x, new Object[] {s.get(x).getidno(),s.get(x).getname(),subselected,s.get(x).getfirst(), s.get(x).getsecond(),s.get(x).getthird(),s.get(x).getfourth()});
           val = s.get(x).getidno();
           name = s.get(x).getname();
           sub1  = s.get(x).getsy();
           
             gradeList2 = mi.getList4("gradeManage1",val);
                ArrayList<GradesNew> uu1 = new ArrayList<GradesNew>();
                
                for (int x11 = 0; x11 < gradeList2.size(); x11++) {
                    uu1.add((GradesNew) gradeList2.get(x11));
                    ggrade = uu1.get(x11).getgrade();
                    gquartername = uu1.get(x11).getquartername();
                    gsubject = uu1.get(x11).getsubject();

                       if(gquartername.equals("First Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
                    for (int x111 = 0; x111 < uu1.size(); x111++) {
                    dtm.setValueAt(ggrade, x, 3);
                }
                }else if(gquartername.equals("Second Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
                for (int x111 = 0; x111 < uu1.size(); x111++) {
                    dtm.setValueAt(ggrade, x, 4);
                }
                }else if(gquartername.equals("Third Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
                for (int x111 = 0; x111 < uu1.size(); x111++) {
                    dtm.setValueAt(ggrade, x, 5);
                }
                }else if(gquartername.equals("Fourth Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
                for (int x111 = 0; x111 < uu1.size(); x111++) {
                    dtm.setValueAt(ggrade, x, 6);
                }
                }
                    
                }
                
             
           
            }
        }catch(Exception e){
        } 
         
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      
       
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        
//        try{   
//        int looper = 0;
//        int first1 = 0;
//        int second1 = 0;
//        int third1 = 0;
//        int fourth1 = 0;
//        int ave = 0;
//        String stat = null;
//         int rc = gaGradeTbl.getRowCount()-1;
//         
//            ArrayList<Grades1> s1 = new ArrayList<Grades1>();
//            for(int x1 = 0; x1 < list1.size(); x1++) {
//                Grades1 a1 = (Grades1) list1.get(x1);
//                if(a1.getsection().equals(sy)) s1.add((Grades1) list1.get(x1));
//                 
//            }
//                for(int x1= 0; x1 < s1.size(); x1++) {
//                 a3 = s1.get(x1).getstuID();
//   
//                 
//        String first = (String) gaGradeTbl.getValueAt(looper, 3);
//         first1 = Integer.parseInt(first);
//        String second = (String) gaGradeTbl.getValueAt(looper, 4);
//         second1 = Integer.parseInt(second);
//        String third = (String) gaGradeTbl.getValueAt(looper, 5);
//         third1 = Integer.parseInt(third);
//        String fourth = (String) gaGradeTbl.getValueAt(looper, 6);
//         fourth1 = Integer.parseInt(fourth);
//         ave = (first1+second1+third1+fourth1)/4;
//        if(ave<75){
//            stat="Failed";
//        } else{
//            stat = "Passed";
//        }
//        
//
//                System.out.println(first1);
//                System.out.println(second1);
//                System.out.println(third1);
//                System.out.println(fourth1);
//                System.out.println(ave);
//                System.out.println(stat);
//                System.out.println(a2);
//                System.out.println(subres1);
////                mi.addGrade(first1, second1, third1, fourth1, ave, stat, a3, subres1, cUser);
//                  JOptionPane.showMessageDialog(null, "Grade Successfully Added", "OK", 1);
//                 looper++;
//                 jComboBox1.removeItem(combo);
//                }
//        
//                
//
//        }catch(Exception e){
//            e.printStackTrace();
//               JOptionPane.showMessageDialog(null, "Error", "Error", 0);
//        }
    }//GEN-LAST:event_jButton1MouseClicked

    private void jComboBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox5ActionPerformed
        try{
             jComboBox1.removeAllItems();
             
              clselected = jComboBox5.getSelectedItem().toString();
               //subjects = mi.getList4("subjectManage", clselected);
              System.out.println(sub1);
              System.out.println(sub2);
                subjects = mi.getList3("subjectManage", sub1, sub2);
                ArrayList<Subject> s12 = new ArrayList<Subject>();   
                for(int x12 = 0; x12 < subjects.size(); x12++) {
                s12.add((Subject) subjects.get(x12));                
                subres1 = s12.get(x12).getSubjName();
                subres2 = s12.get(x12).getsubID();
                jComboBox1.addItem(subres1);   
            }
                  list = mi.getList4("gradeManage2",clselected);
            ArrayList<Grades1> s = new ArrayList<Grades1>();
            for(int x = 0; x < list.size(); x++) {
                Grades1 a = (Grades1) list.get(x);
                s.add((Grades1) list.get(x));
            
            }
            
            dtm = new DefaultTableModel(new String[] {gaGradeTbl.getColumnName(0), gaGradeTbl.getColumnName(1), gaGradeTbl.getColumnName(2), gaGradeTbl.getColumnName(3), gaGradeTbl.getColumnName(4), gaGradeTbl.getColumnName(5), gaGradeTbl.getColumnName(6), gaGradeTbl.getColumnName(7)}, 0);
            gaGradeTbl.setModel(dtm);
            for(int x = 0; x < s.size(); x++) {
//                String a = s.get(x).getidno();
//                String a1 = s.get(x).getname(); // name
//                String a2 = s.get(x).getsection();//syname
                a2 = s.get(x).getstuID();
                sub2  = s.get(x).getcname();
                
               // System.out.println(a2);
    
          //  gaGradeTbl.removeAll();
           dtm.insertRow(x, new Object[] {s.get(x).getidno(),s.get(x).getname(),combo,s.get(x).getfirst(), s.get(x).getsecond(),s.get(x).getthird(),s.get(x).getfourth()});
           val = s.get(x).getidno();
           name = s.get(x).getname();
           sub1  = s.get(x).getsy();
           
            }
            
            
              
        }catch(Exception e){
        }
    }//GEN-LAST:event_jComboBox5ActionPerformed

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
         try {
            int looper = 0;
            int first1 = 0;
            double first2 = 0;
            double second2 = 0;
            double third2 = 0;
            double fourth2 = 0;
            int q1 = 1;
            int q2 = 2;
            int q3 = 3;
            int q4 = 4;

            ArrayList<Grades1> s1 = new ArrayList<Grades1>();
            for (int x1 = 0; x1 < list1.size(); x1++) {
                Grades1 a1 = (Grades1) list1.get(x1);
                if (a1.getsection().equals(sy)) {
                    s1.add((Grades1) list1.get(x1));
                }

            }
            
            
            int x = gaGradeTbl.getSelectedColumn();
            while (x != 0) {
                x--;
            }
            int y = gaGradeTbl.getSelectedRow();
            val = (String) gaGradeTbl.getValueAt(y, x);
            //for (int x1 = 0; x1 < s1.size(); x1++) {
                a3 = val;
                a33 = Integer.parseInt(a3);
                
                String first = (String) gaGradeTbl.getValueAt(looper, 3);
                String second = (String) gaGradeTbl.getValueAt(looper, 4);
                String third = (String) gaGradeTbl.getValueAt(looper, 5);
                String fourth = (String) gaGradeTbl.getValueAt(looper, 6);
                first2 = Double.parseDouble(first);
                second2 = Double.parseDouble(second);
                third2 = Double.parseDouble(third);
                fourth2 = Double.parseDouble(fourth);
                
                System.out.println(first2);
                System.out.println(second2);
                System.out.println(third2);
                System.out.println(fourth2);
                System.out.println(a33);
                System.out.println(subselected);
                System.out.println(sy);
                
                
                
                mi.editGrade(first2,a33,q1,subselected,sy);
                mi.editGrade(second2,a33,q2,subselected,sy);
                mi.editGrade(third2,a33,q3,subselected,sy);
                mi.editGrade(fourth2,a33,q4,subselected,sy);
                
              
                
                
                //looper++;
                JOptionPane.showMessageDialog(null, "Grade Successfully Added", "OK", 1);
                
                
               //jComboBox1.removeItem(combo);
           // }

            

        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Error", "Error", 0);
            System.out.println(e);
        }
    }//GEN-LAST:event_jButton3MouseClicked

    
   
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AddGrades.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AddGrades.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AddGrades.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AddGrades.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new AddGrades(mi,cUser).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel bannerL;
    private javax.swing.JLabel dateL;
    private javax.swing.JTable gaGradeTbl;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane48;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToggleButton jToggleButton2;
    private javax.swing.JToggleButton jToggleButton3;
    private javax.swing.JToggleButton jToggleButton4;
    private javax.swing.JLabel timeL;
    // End of variables declaration//GEN-END:variables
}
